package cn.llssit.controller;

import cn.llssit.framework.web.controller.BaseController;
import cn.llssit.framework.web.domain.AjaxResult;
import cn.llssit.project.wechatapi.domain.MovieSwiper;
import cn.llssit.project.wechatapi.mapper.MovieSwiperMapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: Lesan
 * @Date: 2020-06-29
 */
@RestController
@RequestMapping("/swiper")
public class MovieSwiperController extends BaseController {
    @Autowired
    MovieSwiperMapper movieSwiperMapper;

    @ApiOperation("")
    @GetMapping("/list")
    public AjaxResult getList(Integer pageNum, Integer pageSize,String status,String type){
        if (status==null&&type==null){
            startPage();
            List<MovieSwiper> swipers = movieSwiperMapper.selectAll();
            return AjaxResult.success(getDataTable(swipers));
        }
        if (status!=null){
            startPage();
            List<MovieSwiper> movieSwipers = movieSwiperMapper.selectStatus(status);
            return AjaxResult.success(getDataTable(movieSwipers));
        }
        if (type!=null){
            startPage();
            List<MovieSwiper> movieSwipers = movieSwiperMapper.selectType(type);
            return AjaxResult.success(getDataTable(movieSwipers));

        }
        return AjaxResult.error();
    }

    @ApiOperation("")
    @GetMapping("/getSwiperById")
    public AjaxResult getByid(Integer id){
        return AjaxResult.success(movieSwiperMapper.selectById(id));
    }

    @ApiOperation("")
    @PostMapping("/addItem")
    public AjaxResult addItem(@RequestBody MovieSwiper movieSwiper){
        movieSwiperMapper.insertItem(movieSwiper);
        return AjaxResult.success();
    }

    @ApiOperation("")
    @PutMapping("/updateItem")
    public AjaxResult updateItem(@RequestBody MovieSwiper movieSwiper){
        movieSwiperMapper.updateItem(movieSwiper);
        return AjaxResult.success();
    }

    @ApiOperation("")
    @DeleteMapping("/deleteItem/{ids}")
    public AjaxResult deleteItem(@PathVariable Integer[] ids){
        for (Integer id : ids){
            movieSwiperMapper.DeleteById(id);
        }
        return AjaxResult.success();
    }
}
